package one.stand.service;

import com.alibaba.fastjson.JSON;
import one.stand.OneCrmServiceApplicationTests;
import one.stand.request.BusinessCardRequest;
import one.stand.request.CompanyCustomerLableRequest;
import one.stand.request.CustomerRequest;
import one.stand.request.InputDealMoneyRequest;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.TestConfiguration;

import java.util.ArrayList;
import java.util.List;

@TestConfiguration
public class Customer extends OneCrmServiceApplicationTests {
    @Autowired
    CustomerService customerService;
    @Autowired
    InputDealMoneyService inputDealMoneyService;
    @Autowired
    CompanyCustomerLableService companyCustomerLableService;

    @Test
    public void addLableList() {
        CompanyCustomerLableRequest request = new CompanyCustomerLableRequest();
        request.setCId(67L);
        request.setId(121L);
        CompanyCustomerLableRequest request1 = new CompanyCustomerLableRequest();
        request1.setLableName("类型一1");
        request1.setLableId(160);
        List<CompanyCustomerLableRequest> list = new ArrayList<>();
        CompanyCustomerLableRequest request2 = new CompanyCustomerLableRequest();
        request2.setLableName("标签一1");
        request2.setLableColor("#F5F5F6");
        request2.setLableId(161);
        list.add(request2);
        CompanyCustomerLableRequest request3 = new CompanyCustomerLableRequest();
        request3.setLableName("标签二1");
        request3.setLableColor("#F5F5F6");
        request3.setLableId(162);
        list.add(request3);
        request1.setList(list);
        CompanyCustomerLableRequest request4 = new CompanyCustomerLableRequest();
        request4.setLableName("类型二1");
        request4.setLableId(163);
        List<CompanyCustomerLableRequest> list1 = new ArrayList<>();
        CompanyCustomerLableRequest request5 = new CompanyCustomerLableRequest();
        request5.setLableName("标签三1");
        request5.setLableColor("#F5F5F6");
        request5.setLableId(164);
        list1.add(request5);
        CompanyCustomerLableRequest request6 = new CompanyCustomerLableRequest();
        request6.setLableName("标签四1");
        request6.setLableColor("#F5F5F6");
        request6.setLableId(165);
        list1.add(request6);
        request4.setList(list1);
        List<CompanyCustomerLableRequest> list2 = new ArrayList<>();
        list2.add(request1);
        list2.add(request4);
        request.setList(list2);
        System.err.println(JSON.toJSONString(request));
        //companyCustomerLableService.addLableList(request);
    }

    @Test
    public void countCustomer() {
        CustomerRequest request = new CustomerRequest();
        request.setCId(1L);
        System.err.println(JSON.toJSON(customerService.countCustomer(request)));
    }

    @Test
    public void detailInput() {
        InputDealMoneyRequest request = new InputDealMoneyRequest();
        request.setCId(7L);
        request.setCustomerId(1);
        System.err.println(JSON.toJSON(inputDealMoneyService.getInputDealList(request)));
    }

    @Test
    public void getCustomer() {
        CustomerRequest request = new CustomerRequest();
        request.setPageNum(1);
        request.setPageSize(10);
        request.setCId(7L);
        request.setCustomerState(2);
        request.setLableIds(new Integer[]{12,13,19});
        request.setName("L");
        System.err.println(JSON.toJSON(customerService.getCustomer(request,true).getData().size()));
    }

    @Test
    public void getCustomerInfo() {
        System.err.println(JSON.toJSON(customerService.getCustomerInfo(9L)));
    }

    @Test
    public void updCustomerLabel() {
        CustomerRequest request = new CustomerRequest();
        request.setCustomerId(1);
        request.setLableIds(new Integer[]{15, 16, 17});
        System.err.println(JSON.toJSON(customerService.updCustomerLabel(request)));
    }

    @Test
    public void updCustomerState() {
        System.err.println(JSON.toJSON(customerService.updCustomerState(new CustomerRequest() {{
            setCustomerState(1);
            setCustomerId(1);
        }})));
    }
    @Test
    public void manualAdd(){
        CustomerRequest request=new CustomerRequest();
        BusinessCardRequest cardRequest=new BusinessCardRequest();
        cardRequest.setName("test");
        cardRequest.setPhone("123");
        //request.setBusinessCardRequest(cardRequest);
        request.setCustomerState(1);
        request.setLableIds(new Integer[]{13,14});
        request.setId(17L);
        request.setCompanyId(7);

        System.err.println(JSON.toJSON(customerService.manualAdd(request)));
    }

    @Test
    public void updCustomer(){
        BusinessCardRequest cardRequest=new BusinessCardRequest();
        cardRequest.setCardId(24);
        cardRequest.setPosition("123");
        cardRequest.setLogo("test.123");
        cardRequest.setEmail("test");
        CustomerRequest request=new CustomerRequest();
        //request.setBusinessCardRequest(cardRequest);
        System.err.println(JSON.toJSON(customerService.updCustomer(request)));
    }

}
